import 'package:flutter/material.dart';
import '../Pages/Medicinebox.dart';
import '../Settings/Login.dart';
import '../Pages/AddRemind.dart';
import '../Models/medicine.dart';

import '../Settings/Setting.dart';
import '../Pages/MedicineChest.dart';
import '../Pages/MyCenter.dart';
import 'package:flutter/cupertino.dart';
import '../Utils/DataManager.dart';

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() {
    return _TabsState();
  }
}

class _TabsState extends State<Tabs> {
  int _currentIndex=0;

  List _pagelist=[
    //FirstPage(),
    MedicineChest(),
    //SelectPage(),
    MySetting(),
    //MedicineBox()
    //PersonCenter()
    MyCenter(),
  ];
  List _pagetitle=[
    '用药提醒',
    '个人信息中心',
    '个人功能中心'
  ];
  /*void nextPage(String name) async {
    Medicine drug = Medicine(name, "0", [], "片");
    Navigator.pushNamed(context, "addRemind", arguments: {"drug": drug})
        .then((val) {
      Navigator.pop(context, val);
    });
  }*/

  _addDrug() async {
    Medicine drug = Medicine("药", "0", [], "片");
    await Navigator.pushNamed(context, "addRemind",arguments: {"drug": drug})
        .then((val) {
      if (val != null) {
        Medicine drug = val;
        setState(() {
          dataManager.addMedicine(drug);
          dataManager.save();
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {

    /*Medicine drug = Medicine("旺仔牛奶糖", "0", [], "片");
    dataManager.addMedicine(drug);
    dataManager.save();*/

    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(this._pagetitle[this._currentIndex]),
      ),
      body: this._pagelist[this._currentIndex],//在数组中找到当前下标的页面
      floatingActionButton: Container(
        height: 70,
        width: 70,
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(35),
          color: Colors.white,
        ),
        child: FloatingActionButton(
          child: Icon(
            Icons.add,
            size: 30,
          ),
          onPressed: () {
            print("进入添加页面");
            _addDrug();
          }
        ),
      ),

      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,


      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index){
          setState(() {//实现确定当前页面下标
            this._currentIndex=index;
          });
        },
        items: [
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.home), title: Text('提醒清单')),
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.add_circled_solid), title: Text('  ')),
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.person), title: Text('功能目录'))
        ],
      ),
      drawer: Drawer(
        child: MySetting(),
      ),
    );
  }
}